package com.jzz.eletuanbackend.controller;

import com.jzz.eletuanbackend.service.BusinessService;
import com.jzz.eletuanbackend.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @PostMapping("/shop/new")
    public Msg newShop(
            @RequestParam("user_id") Long userId,
            @RequestParam("contact") String contact,
            @RequestParam("name") String name,
            @RequestParam("desc") String description,
            @RequestParam("loc") String displayLocation,
            @RequestParam("lng") Double lng,
            @RequestParam("lat") Double lat,
            @RequestParam("licenseId") String licenseId,
            @RequestParam("startPrice") Double startPrice,
            @RequestParam("shipPrice") Double shipPrice
    ) {
        return businessService.newShop(userId, contact, name, description, displayLocation, lng, lat, licenseId, startPrice, shipPrice);
    }

    @RequestMapping("/shop/list")
    public Msg listShops(@RequestParam("user_id") Long userId) {
        return businessService.listShops(userId);
    }

    @PostMapping("/shop/open")
    public Msg openShop(@RequestParam("shopId") Long shopId) {
        return businessService.openShop(shopId);
    }

    @PostMapping("/shop/close")
    public Msg closeShop(@RequestParam("shopId") Long shopId) {
        return businessService.closeShop(shopId);
    }

    @PostMapping("/shop/delete")
    public Msg unregisterShop(@RequestParam("shopId") Long shopId) {
        return businessService.unregisterShop(shopId);
    }

    @PostMapping("/shop/edit")
    public Msg editShop(
            @RequestParam("id") Long id,
            @RequestParam("startPrice") Double startPrice,
            @RequestParam("shipPrice") Double shipPrice,
            @RequestParam("desc") String desc
    ) {
        return businessService.editShop(id, startPrice, shipPrice, desc);
    }

    @RequestMapping("/shop/get")
    public Msg getShop(@RequestParam("id") Long id) {
        return businessService.getShop(id);
    }

    @PostMapping("/block/add")
    public Msg blockAdd(@RequestParam("shopId") Long shopId, @RequestParam("name") String name) {
        return businessService.blockAdd(shopId, name);
    }

    @PostMapping("/block/remove")
    public Msg blockRemove(@RequestParam("blockId") Long blockId) {
        return businessService.blockRemove(blockId);
    }

    @PostMapping("/item/get")
    public Msg itemGet(@RequestParam("id") Long id) {
        return businessService.itemGet(id);
    }

    @PostMapping("/item/add")
    public Msg itemAdd(@RequestParam("blockId") Long blockId,
                       @RequestParam("name") String name,
                       @RequestParam("image") String image,
                       @RequestParam("description") String description,
                       @RequestParam("specifications") String specifications,
                       @RequestParam("price") Double price,
                       @RequestParam("minQuantity") Integer minQuantity,
                       @RequestParam("packPrice") Double packPrice) {
        return businessService.itemAdd(blockId, name, image, description, specifications, price, minQuantity, packPrice);
    }

    @PostMapping("/item/edit")
    public Msg itemEdit(@RequestParam("itemId") Long id,
                        @RequestParam("blockId") Long blockId,
                        @RequestParam("name") String name,
                        @RequestParam("image") String image,
                        @RequestParam("description") String description,
                        @RequestParam("specifications") String specifications,
                        @RequestParam("price") Double price,
                        @RequestParam("minQuantity") Integer minQuantity,
                        @RequestParam("packPrice") Double packPrice) {
        return businessService.itemEdit(id, blockId, name, image, description, specifications, price, minQuantity, packPrice);
    }

    @PostMapping("/item/remove")
    public Msg itemRemove(@RequestParam("itemId") Long id) {
        return businessService.itemRemove(id);
    }

    @PostMapping("/order/accept")
    public Msg acceptOrder(@RequestParam("orderId") Long orderId) {
        return businessService.acceptOrder(orderId);
    }

    @RequestMapping("/order/get")
    public Msg getOrder(@RequestParam("orderId") Long id) {
        return businessService.getOrder(id);
    }

    @RequestMapping("/order/all")
    public Msg getAllOrders(@RequestParam("user_id") Long userId) {
        return businessService.getAllOrders(userId);
    }

    @RequestMapping("/order/shop")
    public Msg getShopOrders(@RequestParam("shopId") Long shopId) {
        return businessService.getShopOrders(shopId);
    }
}
